/*************************************************
Author: tony
Date: 07/23/2013
Description:
Notes:
*************************************************/

#ifndef __CQQMallMgr_h__
#define __CQQMallMgr_h__

#include "commerrno.h"
#include "commclass.h"
#include "CTArray.h"
#include "CQQMallConfig.h"
#include "MsgQQMall.pb.h"

class CCmdApi;
class CDropItem;
class MsgTips;
class CPlayerDetailInfoEx1;

class CQQMallMgr
{
public:
    CQQMallMgr ()
    {
        _uiSendTipsGoodsId = 0;
    }

    int Init (const char * szBuff)   { return _stConfig.Init(szBuff); }
    static size_t CountSize()        { return CQQMallConfig::CountSize(); }

    int LoadConfig(const char* szCfgPath);

    void GetMallTabContext (CUserQQMall & stUserMall, EN_MALL_TAB_TYPE enTab, MsgAnsQQMall & stAns);

    int GetMallDropGoods (unsigned int uiGoodsId, int iNum, CDropItem & stDropItem);

    int GetMallGoodsVipExp (unsigned int uiGoodsId, int iNum);

    int InitBuyGoodsCmd (unsigned int uiGoodsId, int iNum, int iMaxNum, CCmdApi * pstCmd);

    bool IsValidGoodsId (unsigned int uiGoodsId);

    unsigned int GetQuickBuyGoodsId (unsigned char ucItemType, unsigned short usItemCfgId);

    int CheckCanBuy (CUserQQMall & stUserMall, int iNowTime, MsgReqQQMall & stReq);

    int CheckBuyLimit (CUserQQMall & stUserMall, unsigned int uiGoodsId, int iNums, int iNowTime);

    int AddBuyedLimitGoods (CPlayerDetailInfoEx1 & stPlayerDetailEx1, unsigned int uiGoodsId, int iNums, int iNowTime);

    bool IsLimitGoods (unsigned int uiGoods);

    void SendLimitInfoToFront (CUserQQMall & stUserMall, unsigned int uiGid, unsigned char ucTabType);

    int GetMaxBuyNum (CUserQQMall & stUserMall, unsigned int uiGoodsId, int iNowTime);

    void ProcCrossDay (int iNowTime);

    void CheckAndSendTips (unsigned int uiGID);

    const CMallGoodsUnit & GetGoodUnit (unsigned int uiGoodsId);

private:
    void SendNewGoodsTips (unsigned int uiGid, MsgTips & stTips);
    void GetNewGoodsTips (MsgTips & stTips);

    void RefreshSendTipsGoodID (int iNowTime);
    void GetMallGoodsInfo (unsigned int uiGoodsId, MsgMallGoods * pstMsg);
    CQQMallConfig _stConfig;
    unsigned int _uiSendTipsGoodsId;
};

#endif // __CQQMallMgr_h__
